import requests
from config import BASE_URL, TOKEN


class IHRMEmpApi:
    @classmethod
    def add(cls, data):
        """
        添加员工
        :param data: dict
        """
        add_url = BASE_URL + "/api/sys/user"
        headers = {
            "Content-Type": "application/json",
            "Authorization": TOKEN
        }

        r = requests.post(add_url, headers=headers, json=data)

        return r

    @classmethod
    def delete(cls, emp_id):
        """删除员工"""
        url = BASE_URL + f"/api/sys/user/{emp_id}"

        headers = {
            "Authorization": TOKEN
        }
        r = requests.delete(url, headers=headers)
        return r

    @classmethod
    def update(cls, emp_id, data):
        """修改员工信息"""
        url = BASE_URL + f"/api/sys/user/{emp_id}"
        headers = {
            "Content-Type": "application/json",
            "Authorization": TOKEN
        }
        r = requests.put(url, headers=headers, json=data)
        return r
        pass

    @classmethod
    def select(self, emp_id):
        """查询员工信息"""
        url = BASE_URL + f"/api/sys/user/{emp_id}"
        headers = {
            "Authorization": TOKEN
        }
        r = requests.get(url, headers=headers)
        return r


if __name__ == '__main__':
    # data = {
    #     "username": "张三",
    #     "mobile": "15012343248",
    #     "workNumber": "9527"
    # }
    # resp = IHRMEmpApi.add(data)
    # print(resp.status_code)
    # print(resp.json())

    # data = {"username": "王五"}
    # resp = IHRMEmpApi.update('1603303447648546816', data)
    # print(resp.status_code)
    # print(resp.json())

    # resp = IHRMEmpApi.delete('1603303447648546816')
    # print(resp.status_code)
    # print(resp.json())

    resp = IHRMEmpApi.select('1603303447648546816')
    print(resp.status_code)
    print(resp.json())
